const { DataTypes } = require("sequelize");
const sequelize = require("../config/sequelize");
const User = require("./user");
const Food = require("./food");
const Sports = require("./sports");
const Topic = require("./topic");

const Collect = sequelize.define(
  "Collect",
  {
    collectId: {
      type: DataTypes.STRING,
      comment: "收藏id",
    },
    collectType: {
      type: DataTypes.STRING,
      comment: "收藏类型",
    },
  },
  {
    sequelize: sequelize,
    tableName: "collect",
    underscored: true, //显示在数据库字段为下划线
  }
);

// 关联user表
Collect.belongsTo(User, {
  foreignKey: "userId",
  constraints: false,
  as: "user",
});
// 关联food表
Collect.belongsTo(Food, {
  foreignKey: "collectId",
  constraints: false,
  as: "food",
});
// 关联sports表
Collect.belongsTo(Sports, {
  foreignKey: "collectId",
  constraints: false,
  as: "sports",
});
Collect.belongsTo(Topic, { 
  foreignKey: 'collectId', 
  constraints: false ,
  as:'topic'
});

module.exports = Collect;
